//
//  SearchViewController.m
//  YiqiMobile
//
//  Created by henry on 13-4-6.
//  Copyright (c) 2013年 henry. All rights reserved.
//

#import "SearchViewController.h"
#import "Utility.h"
#import "Config.h"
#import "SearchListViewController.h"

@interface SearchViewController ()

@end

@implementation SearchViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad{
    [super viewDidLoad];
    self.navigationItem.titleView=[Utility getTitleView:@"搜索"];
	// Do any additional setup after loading the view.
    
    UIImageView *view=[[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 300, 34)];
    view.backgroundColor=[UIColor colorWithPatternImage:[Utility imageNamed:@"searchbar_bg.png"]];
    self.searchField = [[UITextField alloc] initWithFrame:CGRectMake(30, 0, 268, 33)];
    self.searchField.placeholder=@"请输入关键字搜索";
    self.searchField.delegate=self;
    self.searchField.autocorrectionType = UITextAutocorrectionTypeNo;
    self.searchField.returnKeyType=UIReturnKeyNext;
    self.searchField.clearButtonMode=UITextFieldViewModeWhileEditing;
    self.searchField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    self.searchField.backgroundColor=[UIColor  clearColor];
    self.searchField.borderStyle=UITextBorderStyleNone;
    self.searchField.textColor=[UIColor blackColor];
    self.searchField.font=[UIFont fontWithName:FONT_FAMILY size:12.0f];
    self.searchField.autocorrectionType=UITextAutocorrectionTypeNo;
    [self.searchField setBorderStyle:UITextBorderStyleNone];
    self.searchField.returnKeyType = UIReturnKeyDone;
    self.searchField.keyboardType=UIKeyboardTypeDefault;
    [self.searchField becomeFirstResponder];
    [view addSubview:self.searchField];
    
    [self.view addSubview:[Utility customButton:self action:@selector(searachButtonAction:) normalImage:@"search_bowen_normal.png" lightedImage:@"search_bowen_hover.png" frame:CGRectMake(10, 50, 90, 34) title:nil tag:SERACHBUTTONTAG]];
    
    [self.view addSubview:[Utility customButton:self action:@selector(searachButtonAction:) normalImage:@"search_quanzi_normal.png" lightedImage:@"search_quanzi_hover.png" frame:CGRectMake(110, 50, 90, 34) title:nil tag:SERACHBUTTONTAG+1]];
    
    [self.view addSubview:[Utility customButton:self action:@selector(searachButtonAction:) normalImage:@"search_personal_normal.png" lightedImage:@"search_personal_hover.png" frame:CGRectMake(215, 50, 90, 34) title:nil tag:SERACHBUTTONTAG+2]];
    [self.view addSubview:view];
}

-(IBAction)searachButtonAction:(id)sender{
     SearchListViewController *searchListViewController=[[SearchListViewController alloc] initWithNibName:nil bundle:nil];
    UIButton *button=(UIButton*) sender;
    switch (button.tag-SERACHBUTTONTAG) {
        case 0:{
            searchListViewController.titlestr=@"你查找的博文列表";
            //NSLog(@"找博文");
            break;
        }
        case 1:{
             searchListViewController.titlestr=@"你查找的圈子列表";
             //NSLog(@"找圈子");
            break;
        }
        case 2:{
             searchListViewController.titlestr=@"你查找的会员列表";
             //NSLog(@"找人");
            break;
        }
        default:{
            break;
        }
    }
   
   /* if (self.searchField.text.length<1) {
        [Utility customAlertWithMsg:@"请输入关键字" andTitle:@"提醒" andDelagate:nil];
        return;
    }*/
    [searchListViewController loadDataFromServer:self.searchField.text andType:button.tag-SERACHBUTTONTAG];
    [self.navigationController  pushViewController:searchListViewController animated:YES];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
